package cpr.data;

import cpr.Rule;

public class RuleComparable implements Comparable {
	int[] digs;
	public RuleComparable(Rule aRule, HLVector aVector) {
		digs = new int[6];
		digs[5] = aVector.score;
   	 	for (int h = 0; h < Rule.HLIS.length; h++) {
            int hlIndex = Rule.HLH[h][aVector.getValue(h)];
            digs[h] = aRule.getHLValueDigital(hlIndex);
        }
	}
	
	public int compareTo(Object o) {
		RuleComparable that = (RuleComparable)o;
		
		int d=0;
		for (int i = 0; i < digs.length; i++) {
			d= digs[i]-that.digs[i];
			if (d!=0) {
				return d;
			}
		}
		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		return compareTo(obj)==0;
	}

	@Override
	public int hashCode() {
		
		int hash =0;
		for (int i = 0; i < digs.length; i++) {
			hash += digs[i];
			hash += (hash<<10);
			hash ^= (hash>>6);
		}
		hash += (hash << 3);
		hash ^= (hash >> 11);
		hash += (hash << 15);
		return hash;
		
	}
	
	
	
}